home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / uproot.arc / UPROOT.C next >
C/C++ Source or Header  |  1985-11-20  |  3KB  |  134 lines

  1. /*
  2.  *    UPROOT.TTP
  3.  *
  4.  * A program to make TOS forget its directory tree for a drive.
  5.  * Drive letter taken from command line  (Default: C).
  6.  * Waits for keypress when done, unless a second argument is given.
  7.  * Use periodically on RAM and HARD disks to avoid TOS bug.
  8.  *
  9.  *               >>> WARNING <<<
  10.  *
  11.  *    Using this program does _NOT_ break the 40-folder limit!
  12.  *      It only avoids the crashes that occur after the same
  13.  *             few folders are reopened many times.
  14.  *
  15.  *  By Moshe Braner,        870401.
  16.  */
  17.  
  18. #include <osbind.h>
  19.  
  20. #define WORD    int    /* 16 bits: 'int' in Megamax */
  21.  
  22. typedef struct bpb {
  23.     WORD    recsiz;
  24.     WORD    clsiz;
  25.     WORD    clsizb;
  26.     WORD    rdlen;
  27.     WORD    fsiz;
  28.     WORD    fatrec;
  29.     WORD    datrec;
  30.     WORD    numcl;
  31.     WORD    bflags;
  32. } BPB;
  33.  
  34. /*
  35.  * routine to send a one-shot media-definitely-changed
  36.  * message to GEMDOS (via Rwabs).
  37.  */
  38. extern dmch();
  39. extern drvnum();
  40. asm
  41. {
  42. dmch:    MOVEA.W    #0x476,A0        /* Rwabs() vector    */
  43.     LEA    oldvec(PC),A1
  44.     MOVE.L    (A0),(A1)        /* save old        */
  45.     LEA    tmpvec(PC),A1
  46.     MOVE.L    A1,(A0)            /* poke new        */
  47.     RTS
  48. tmpvec:    MOVE.W    drvnum(PC),D0
  49.     CMP.W    14(A7),D0        /* target drive?    */
  50.     BEQ.S    now
  51.     MOVE.L    oldvec(PC),A0        /* do normal        */
  52.     JMP    (A0)
  53. now:    MOVE.L    oldvec(PC),0x476    /* restore normal Rwabs    */
  54.     MOVEQ    #-14,D0            /* "media has changed"    */
  55.     RTS
  56. oldvec:    DC.L    0
  57. drvnum:    DC.W    0
  58. }
  59.  
  60. /*
  61.  * Print a long integer as a string.
  62.  */
  63. prtli(n)
  64.     register long n;
  65. {
  66.     register char *p;
  67.     char    a[20];
  68.  
  69.     p = &a[19];
  70.     *p = 0;
  71.     do {
  72.         *(--p) = (n%10) + '0';
  73.         n /= 10;
  74.     } while (n);
  75.     Cconws(p);
  76. }
  77.  
  78. main(argc, argv)
  79.     int    argc;
  80.     char    *argv[];
  81. {
  82.     register int c;
  83.     int    drv, bps, spc, verbose;
  84.     long    bytes, dinfo[4];
  85.     BPB    *bpb;
  86.  
  87.     /* get command line arguments */
  88.  
  89.     c = 'C';        /* default    */
  90.     if (argc > 1) {
  91.         c = argv[1][0];
  92.         if (c>='a' && c<='p')
  93.             c += 'A'-'a';
  94.         if (c < 'A' || c > 'P')
  95.             c = 'C';
  96.     }
  97.     drv = c-'A';        /* 0=A, 1=B, ... */
  98.  
  99.     if (argc > 2)
  100.         verbose = 0;
  101.     else
  102.         verbose = 1;    /* default    */
  103.  
  104.     if (verbose)
  105.         Cconws("\033E\r\n\n\tUPROOT\t\tv1.0\t\tby Moshe Braner\r\n\n");
  106.  
  107.     /* get disk parameters from bios parameter block */
  108.  
  109.     bpb = (BPB *) Getbpb(drv);
  110.     bps = bpb->recsiz;        /* bytes per sector        */
  111.     spc = bpb->clsiz;        /* sectors per cluster        */
  112.  
  113.     /*
  114.      * Do our main thing:
  115.      *     Force a media-HAS-changed message onto GEMDOS!
  116.      */
  117.  
  118.     *((int *)&drvnum) = drv;
  119.     Supexec(&dmch);        /* install media-HAS-changed code    */
  120.     Dfree(dinfo,drv+1);    /* call it through GEMDOS        */
  121.  
  122.     if (! verbose)
  123.         exit(0);
  124.  
  125.     Cconws("\tDrive has ");
  126.     bytes = dinfo[0] * spc * bps;
  127.     prtli(bytes);
  128.     Cconws(" bytes free out of ");
  129.     bytes = dinfo[1] * spc * bps;
  130.     prtli(bytes);
  131.     Cconws("\r\n\n\tHit any key ");
  132.     Cnecin();
  133. }
  134.